package com.googlecode.nls4j.benchmarks.kvp;

import java.util.EnumSet;
import java.util.Locale;

import com.googlecode.nls4j.CurrentBundle;
import com.googlecode.nls4j.EnumBundleLoader;
import com.googlecode.nls4j.KeyValuePair;
import com.googlecode.nls4j.KeyValuePairStorage;
import com.googlecode.nls4j.NlsContext;

public enum Msg implements KeyValuePair<String> {
    M1("M1 default value"),
    M2("M2 default value"),
    M3("M3 default value");

    private static final CurrentBundle<Msg, String> currentBundle = CurrentBundle
            .newInstance(
                NlsContext.getDefault(),
                new KeyValuePairStorage<Msg, String>(
                        Msg.class, EnumBundleLoader
                                .<Msg, String> getDefault(false), EnumSet
                                .allOf(Msg.class)), false);
    private final String defaultValue;
    private volatile String value;

    private Msg(final String defaultValue) {
        this.defaultValue = value = defaultValue;
    }

    public static CurrentBundle<Msg, String> getCurrentBundle() {
        return currentBundle;
    }

    @Override
    public String getName() {
        return name();
    }

    @Override
    public String getDefaultValue(final Locale locale) {
        return defaultValue;
    }

    @Override
    public String getValue() {
        return value;
    }

    @Override
    public void setValue(final String value) {
        this.value = value;
    }

    @Override
    public String toString() {
        return getValue();
    }
}
